<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/12/7
  Time: 21:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <title>Title</title>
    <script type="text/javascript">
        $(function () {
            $("[name='bookName']").blur(function(){
                var bookName = $(this).val(); //当前输入款失去焦点
                $.post("/books/bookExist",{"bookName":bookName},function (date) {
                    if (date.resoult==true){
                        alert("返回的数据"+date.message+"名称"+bookName);
                    }else{
                        alert(date.message);
                    }
                },"json")
            });
        })
    </script>
</head>
<body>
 <form method="post" action="/books/addBooks">
     <table   width="250" align="center">
             <tr align="center">
                 <td>书名：<input type="text" name="bookName">*</td>
             </tr>
             <tr align="center">
                 <td>作者：<input type="text" name="bookAuthor">*</td>
             </tr>
             <tr align="center">
                 <td>出版社：<input type="text" name="bookPublish">*</td>
             </tr>
             <tr>
                 <td align="center">页数：<input type="text" name="bookPage">*</td>
             </tr>
             <tr>
                 <td align="center">价格：<input type="text" name="bookPrice">*</td>
             </tr>
             <tr>
                 <td align="center">
                     <input type="submit" value="提交">
                     <input type="reset" value="重置">
                 </td>
             </tr>

         </table>
 </form>
 <!--提交事件的非空判断-->
 <script type="text/javascript">
     $("form").submit(function(){
         //日期格式的正则表达式
         var bookName=$("[name='bookName']").val();
         var bookAuthor=$("[name='bookAuthor']").val();
         var bookPublish=$("[name='bookPublish']").val();
         var bookPage=$("[name='bookPage']").val();
         var bookPrice=$("[name='bookPrice']").val();
         alert("Nihao ");
         if(bookName=="" || bookAuthor=="" || bookPublish=="" || bookPage=="" || bookPrice==""){
             alert("书名不能为空或全部得填上");
             return false;
         }
         //正整数判断
         var zheng = /^[1-9]+[0-9]*]*$/;
         if (!zheng.test(bookPage)){
            alert("页面数请输入整数");
                return false;
            }
         //数字类型判断
         if(isNaN(bookPrice)){
             alert("价格必须是数字类型");
             return false;
         }
     });
 </script>
</body>
</html>
